package com.watermark.controller;

import com.watermark.model.WatermarkRequest;
import com.watermark.model.WatermarkResponse;
import com.watermark.service.WatermarkService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/watermark")
@RequiredArgsConstructor
@Tag(name = "Watermark API", description = "Image watermarking operations")
public class WatermarkController {
    private final WatermarkService watermarkService;

    @PostMapping(value = "/embed", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Operation(summary = "Embed watermark into image",
              description = "Embeds a watermark image into the original image using deep learning")
    public ResponseEntity<WatermarkResponse> embedWatermark(
            @ModelAttribute WatermarkRequest request) {
        try {
            WatermarkResponse response = watermarkService.embedWatermark(request);
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            return ResponseEntity.internalServerError()
                .body(WatermarkResponse.builder()
                    .message("Error embedding watermark: " + e.getMessage())
                    .build());
        }
    }

    @PostMapping(value = "/extract", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Operation(summary = "Extract watermark from image",
              description = "Extracts the embedded watermark from an image using deep learning")
    public ResponseEntity<WatermarkResponse> extractWatermark(
            @RequestParam("image") MultipartFile watermarkedImage) {
        try {
            WatermarkResponse response = watermarkService.extractWatermark(watermarkedImage);
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            return ResponseEntity.internalServerError()
                .body(WatermarkResponse.builder()
                    .message("Error extracting watermark: " + e.getMessage())
                    .build());
        }
    }
} 